package exer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.MessageFormat;

/**
 * @author tongchen
 * @create 2023-04-01 16:29
 */
@WebServlet("/parameter")
public class GetParameter extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置接收格式
        //req.setCharacterEncoding("utf-8");
        String studentId = req.getParameter("studentId");
        String studentName = req.getParameter("studentName");
        String format = MessageFormat.format("studentId={0},studentName={1}", studentId, studentName);
        //在控制台打印
        System.out.println(format);
        //设置返回格式
       // resp.setContentType("text/html;charset=utf-8");
        //返回数据
        resp.getWriter().write(format);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
